package net.pinnoocle.playadminpc.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.pinnoocle.playcommon.response.BaseResult;
import net.pinnoocle.playdao.entity.admin.SaveShopParams;
import net.pinnoocle.playdao.entity.admin.ShopListSearchVo;
import net.pinnoocle.playdao.entity.admin.ShopListVo;
import net.pinnoocle.playdao.entity.group.UpdateGroup;
import net.pinnoocle.playdao.entity.page.PageModel;
import net.pinnoocle.playservice.service.impl.ShopServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author ye
 * @Description
 * @create 2021-10-19 15:27
 */
@RestController
@RequestMapping("/shop")
@Api(tags = "店铺相关")
@Slf4j
public class ShopController {

    @Autowired
    ShopServiceImpl shopService;

    @GetMapping("list")
    @ApiOperation("店铺列表")
    public BaseResult<PageModel<ShopListVo>> shopList(ShopListSearchVo params){
        return new BaseResult<PageModel<ShopListVo>>().ok(shopService.shopList(params));
    }

    @PostMapping("saveShop")
    @ApiOperation("添加店铺")
    public BaseResult<String> saveShop(@Validated @RequestBody SaveShopParams params){
        boolean result = shopService.saveShop(params);
        if(result){
            return new BaseResult<String>().success("店铺添加成功");
        }
        return new BaseResult<String>().error("店铺添加失败");
    }

    @PostMapping("updateShop")
    @ApiOperation("编辑店铺")
    public BaseResult<String> updateShop(@Validated({UpdateGroup.class}) @RequestBody SaveShopParams params){
        boolean result = shopService.updateShop(params);
        if(result){
            return new BaseResult<String>().success("店铺修改成功");
        }
        return new BaseResult<String>().error("店铺修改失败");
    }

    @GetMapping("deleteShop")
    @ApiOperation("删除店铺")
    public BaseResult<String> deleteShop(@RequestParam("shopId") String shopId){
        boolean result = shopService.deleteShop(shopId);
        if(result){
            return new BaseResult<String>().success("店铺删除成功");
        }
        return new BaseResult<String>().error("店铺删除失败");
    }
}
